// JavaScript Document

//mobile涓嬫媺寮忛伕鍠�
$(document).ready(function(){
    $(".close-sb1").click(function(){
        $("li.inlist1").slideToggle();
    });
});

$(document).ready(function(){
    $(".close-sb2").click(function(){
        $("li.inlist2").slideToggle();
    });
});

$(function () {
    var $window = $(window);
//======header bar==========
    var navLi = $(".nav li"),
        btn_01 = navLi.eq(0),
        sub_01 = navLi.eq(0).find(".intro"),
        btn_03 = navLi.eq(5),
        sub_03 = navLi.eq(5).find(".intro"),
        btn_02 = navLi.eq(13),
        sub_02 = navLi.eq(13).find(".intro");

    btn_01.hover(
        function () {
            sub_01.stop(true, true).slideDown(0);
        },
        function () {
            sub_01.stop(true, true).slideUp(0);
        });


    btn_03.hover(
        function () {
            sub_03.stop(true, true).slideDown(0);
        },
        function () {
            sub_03.stop(true, true).slideUp(0);
        });


    btn_02.hover(
        function () {
            sub_02.stop(true, true).slideDown(0);
        },
        function () {
            sub_02.stop(true, true).slideUp(0);
        });


//===========涓嬫粦bar==========

    $window.scroll(function () {
        if ($(this).scrollTop() > 40) {
            $('#b_01').trigger('mouseleave');
            $('#b_02').trigger('mouseleave');
            $('#b_03').trigger('mouseleave');
            $(".navbarTop").fadeIn("fast");
        } else {
            $(".navbarTop").fadeOut("fast");
        }
    });

    $("#b_01").on('touchstart', function () {
        $("#s_01").stop(true, true).slideDown(300);
    });
    $("#b_02").on('touchstart', function () {
        $("#s_02").stop(true, true).slideDown(300);
    });

    $("#b_01").mouseenter(function () {
        $("#s_01").stop(true, true).slideDown(300);
    }).mouseleave(function () {
        $("#s_01").stop(true, true).slideUp(300);
    });

    $("#b_02").mouseenter(function () {
        $("#s_02").stop(true, true).slideDown(300);
    }).mouseleave(function () {
        $("#s_02").stop(true, true).slideUp(300);
    });
    $("#b_03").mouseenter(function () {
        $("#s_03").stop(true, true).slideDown(300);
    }).mouseleave(function () {
        $("#s_03").stop(true, true).slideUp(300);
    });


//棣栭爜icon
    $(".menu").find("a").addClass("noactive");
    $(".icon_01 a").eq(0).removeClass("noactive").addClass("active");
    $(".icon_02 a").eq(0).removeClass("noactive").addClass("active");
    $(".icon_01").find("a").eq(0).find("span").removeClass("noactive").addClass("activeSpan");
    $(".icon_02").find("a").eq(0).find("span").removeClass("noactive").addClass("activeSpan");

    $(".icon_01 a").mouseover(function () {
        var now = $(this).index();
        var nowBar = $(this).position().left;
        var move = nowBar;
        $(".icon_01 a").eq(now).removeClass().addClass("active");
        $(".icon_01 a").eq(now).siblings().removeClass().addClass("noactive");
        $(".icon_01 a").find("span").removeClass("activeSpan");
        $(".icon_01").find("a").eq(now).find("span").removeClass("noactive").addClass("activeSpan");
        $(".pd div").find("p").eq(now).fadeIn(300);
        $(".pd div").eq(now).siblings().find("p").fadeOut(300);
        $(".tipBar_01").stop(true, false).animate({left: move}, 300);
    });

    $(".icon_02 a").mouseover(function () {
        var now = $(this).index();
        var nowBar = $(this).position().left;
        var move = nowBar;
        $(".icon_02 a").eq(now).removeClass().addClass("active");
        $(".icon_02 a").eq(now).siblings().removeClass().addClass("noactive");
        $(".icon_02 a").find("span").removeClass("activeSpan");
        $(".icon_02").find("a").eq(now).find("span").removeClass("noactive").addClass("activeSpan");
        $(".pd_02 div").find("p").eq(now).fadeIn(300);
        $(".pd_02 div").eq(now).siblings().find("p").fadeOut(300);
        $(".tipBar").stop(true, false).animate({left: move}, 300);
    });


//宸﹀伌婊戦枊閬稿柈
    var sidebar = $("#toggle-sidebar"),
        sideBarOpen = false,
        $wrap = $("#wrap"),
        $upermain = $(".upermain");
    sidebar.on("click", sildeRight);
    //寰€鍙抽倞婊戝嚭
    function sildeRight() {
        sideBarOpen = true;
        $(".main-sidebar").fadeIn(0);
        $wrap.animate({left: "-45%"}, 300);
        $upermain.animate({left: "0%"}, 300);
        $(".MgoBTN").animate({left: "-45%"}, 300);
        $("#main-navbar").animate({left: "-45%"}, 300);
        $("#topHeaderImg_fixed_M").animate({left: "-45%"}, 300);
        $("#gomb_02").animate({left: "-45%"}, 300);
        sidebar.css("color", "#E7452B");
        sidebar.on("click", sildeLeft);
        $wrap.on("click", sildeLeft);
        $upermain.on("click", sildeLeft);
        sidebar.off("click", sildeRight);
    }

    //鍥炲師渚嗙殑浣嶇疆
    function sildeLeft() {
        sideBarOpen = false;
        $(".main-sidebar").delay(200).fadeOut(0);
        $wrap.animate({left: "0"}, 300);
        $upermain.animate({left: "0"}, 300);
        $(".MgoBTN").animate({left: "0"}, 300);
        $("#main-navbar").animate({left: "0"}, 300);
        $("#gomb_02").animate({left: "0"}, 300);
        $("#topHeaderImg_fixed_M").animate({left: "0"}, 300);
        sidebar.css("color", "#d4d4d4");
        sidebar.on("click", sildeRight);
        sidebar.off("click", sildeLeft);
        $wrap.off("click", sildeLeft);
        $upermain.off("click", sildeLeft);
    }

    if ($window.innerWidth() < 750) {
        $wrap.swipe({
            swipeRight: function (event, direction, distance, duration, fingerCount, fingerData, currentDirection) {
                if (sideBarOpen) {
                    sildeLeft();
                }
            }
        });
        $upermain.swipe({
            swipeRight: function (event, direction, distance, duration, fingerCount, fingerData, currentDirection) {
                if (sideBarOpen) {
                    sildeLeft();
                }
            }
        });
    }






    //姣旇純琛ㄦ牸
    $window.scroll(function () {
        if ($(this).scrollTop() > 400) {

            $(".topHeaderImg_fixed").fadeIn(0);
        } else {
            $(".topHeaderImg_fixed").fadeOut(0);
        }
    });

    //棣栭爜鎵嬫鐗堣〃鏍煎垏鎻�
    $(".cho_btn li").eq(0).removeClass().addClass("cho_btn_li_active");
    $(".cho_btn li").click(function () {
        var nowtab = $(this).index();
        $(this).removeClass().addClass("cho_btn_li_active");
        $(this).siblings().removeClass().addClass("cho_btn_li");
        $(".list div").eq(nowtab).fadeIn(0);
        $(".list div").eq(nowtab).siblings().fadeOut(0);


    })

    //gotoTOP
    $(".gotoTop").click(function () {
        $("html,body").animate({scrollTop: 0}, 900);
        return false;
    });
    $window.scroll(function () {
        if ($(this).scrollTop() > 20) {
            $(".gotoTop").fadeIn(0);
        } else {
            $(".gotoTop").fadeOut(0);
        }
    });

    //鎵嬫鏉縯able title
    //鍏堟劅鎳夋痪鍒扮殑浣嶇疆
    var fixedtop = $(".topHeaderImg").offset().top + $(".topHeaderImg").innerHeight() - 150,
        menuTop = $(".main-navbar-fixed-top"),
        bannertop = menuTop.height(),
        tableHead = $("#topHeaderImg_fixed_M"),
        headerHH = tableHead.height(),
        bottomHH = $("#gomb").offset().top,
        mobileTableOffset = $("#TableList_M").height() - $(".main-navbar").height() - $(".pro_banner").height(),
        actionBtnTop = tableHead.innerHeight(),
        actionBtns = $("#gomb_02");

    console.log(fixedtop);


    $window.scroll(function () {
        if ($(this).scrollTop() > fixedtop) {
            // tableHead.stop(true, false).animate({top:bannertop},0);
            menuTop.stop(true, false).animate({top: -bannertop}, 0);
            actionBtns.stop(true, false).animate({top: 0}, 0);
            tableHead.stop(true, false).animate({top: -actionBtnTop}, 0);

            //鏄惁椤ずfixed header 涓嬫柟涓夐button
            // actionBtns.show();
        } else {
            // tableHead.stop(true, false).animate({top:0},0)
            menuTop.stop(true, false).animate({top: 0}, 0);
            actionBtns.stop(true, false).animate({top: -actionBtnTop}, 0);
            tableHead.stop(true, false).animate({top: -actionBtnTop}, 0);
            //鏄惁椤ずfixed header 涓嬫柟涓夐button
            // actionBtns.hide();
        }
    });


    /* 鍘熸湰鎸夐垥鍒ゆ柗
     $window.scroll(function() {
     if ( $(this).scrollTop()<mobileTableOffset){
     $("#gomb_02").fadeIn(0);
     } else {
     $("#gomb_02").fadeOut(0);
     }
     });

     $window.scroll(function() {
     if ( $(this).scrollTop()<=0){
     $("#gomb_02").fadeOut(0);
     }
     });*/


})